package com.cwx.mychat.entity.enums;

/**
 * 错误码和错误定义类
 * 错误码定义为5位数字
 * 前两位表示业务场景，后三位表示错误码
 * 例如： 10001：
 *      10: 通用
 *          001表示系统未知异常
 *      11：用户
 *      12：群聊
 *      13: 消息
 *      14: 文件
 */
public enum ExceptionBizCodeEnum {
    UNKNOWN_EXCEPTION(10000, "系统未知异常"),
    VALID_EXCEPTION(10001, "参数格式校验失败"),
    SMS_CODE_EXCEPTION(10002, "验证码获取评率太高，稍后再试"),
    IMAGE_VALID_EXCEPTION(10003, "图片验证码不正确！"),
    LOGIN_VERIFICATION_FAILED(10005, "登录校验失败"),
    REDIS_CACHE_FAILED(10006, "Redis存入失败"),
    REDIS_DELETE_FAILED(10007, "redis缓存删除失败"),
    JSON_SERIALIZE_EXCEPTION(10008, "JSON序列化异常"),
    MINIO_FILE_EXIST(10009, "minio文件不存在"),
    UPDATE_FAILED(10010, "更新失败"),
    ROBOT_NOT_EXIST(10011, "机器人不存在"),
    REMARK_FORMAT_ERROR(10012, "备注格式错误"),


    EMAIL_EXIST_EXCEPTION(11001, "邮箱已存在"),

    EMAIL_NOT_EXIST_EXCEPTION(11002, "账号不存在，请注册"),
    ACCOUNT_PASSWORD_EXCEPTION(11003, "账号密码错误"),
    ACCOUNT_STOP_EXCEPTION(11004, "账号禁用"),

    ACCOUNT_USING_EXCEPTION(11005, "账号正在使用，请退出后再登录"),
    ACCOUNT_TIMEOUT(11006, "账号超时"),
    ACCOUNT_NO_PERMISSION(11007, "账号无权限"),
    ACCOUNT_FILE_NO_UPLOAD(11008, "用户文件未上传"),
    ACCOUNT_ERROR(11009, "账号错误"),
    ACCOUNT_NOT_LOGIN(11010, "用户未登录"),
    NOT_FOUND_ACCOUNT(11011, "找不到该用户"),
    PHONE_EXIST_EXCEPTION(11012,"手机号已存在"),
    PHONE_FORMAT_EXCEPTION(11013,"手机号格式错误"),
    USER_ID_FORMAT_EXCEPTION(11014,"用户id格式错误"),
    GROUP_MEMBER_FULL(11015, "群聊人员已满"),


    GROUP_NOT_EXIST(12001, "群聊不存在"),
    GROUP_CREATE_COUNT(12003, "最多只能创建5个群聊"),
    GROUP_AVATAR_ERROR(12002, "群头像上传格式错误"),
    GROUP_EXIST(12003, "群聊已经存在"),
    GROUP_CREATE_FAILED(12003, "群聊创建失败"),
    GROUP_DELETE_FAILED(12004, "群聊删除失败"),
    NO_PERMISSION_DELETE_GROUP(12005, "无权删除群组"),
    GROUP_SELECT_FAILED(12006, "群查询失败"),


    MESSAGE_TYPE_ERROR(13001, "消息类型错误"),
    MESSAGE_NOT_EXIST(13002, "消息不存在"),
    MESSAGE_NOT_MATCH_USER(13003, "消息不匹配用户"),
    FILE_UPLOAD_FAILED(14001, "文件上传失败"),
    FILE_FORMAT_ERROR(14002, "文件格式错误"),
    FILE_URL_EXIST(14003, "文件路径不存在"),
    FILE_DOWNLOAD_ERROR(14004, "文件下载失败"),
    FILE_DELETE_ERROR(14005, "文件删除失败"),
    FILE_NOT_EXIST(14006, "文件不存在"),
    FILE_NOT_MATCH_USER(14007, "文件不匹配用户"),

    SESSION_ADD_FAILED(15001, "会话添加失败");


    private Integer code;
    private String msg;
    ExceptionBizCodeEnum(Integer code, String msg){
        this.code = code;
        this.msg = msg;
    }

    public static ExceptionBizCodeEnum getByCode(Integer code){
        for(ExceptionBizCodeEnum item: ExceptionBizCodeEnum.values()){
            if(item.getCode().equals(code)){
                return item;
            }
        }
        return null;
    }

    public Integer getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }
}
